Skip to content

Apply transforms correctly - #230

Closed
Diggsey wants to merge 2 commits into
tamasfe:mainfrom
platformed-com:master
Closed

Diggsey wants to merge 2 commits into
tamasfe:mainfrom
platformed-com:master

Conversation

@Diggsey

@Diggsey Diggsey commented Jul 8, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@jplatte

jplatte commented Jul 9, 2025 •

Copy link
Copy Markdown
Collaborator

The first commit was merged as part of the original PR that proposed it. Can you explain what problem the second commit solves, and maybe even add a test?

@Diggsey

Diggsey commented Jul 9, 2025

Copy link
Copy Markdown
Contributor Author

schemars defines transformations to apply to the schema, for eg. compatibility with OpenAPI. These transforms are defined in the schema settings. When aide accesses sub-schemas via resolve_schema instead of using schemars' root_schema_for and similar methods, those transformations never get applied, meaning the generator settings are ignored.

@shovelmn12

Copy link
Copy Markdown

Any news on version bump?

@jplatte

jplatte commented Sep 12, 2025

Copy link
Copy Markdown
Collaborator

No, sorry.

@jplatte jplatte added this to the 0.16 milestone Dec 27, 2025
@jplatte

jplatte commented Dec 29, 2025

Copy link
Copy Markdown
Collaborator

@Diggsey sorry for the slow feedback. Could you rebase, and add a test for the transforms change?

@jplatte jplatte changed the title Bump schemars and apply transforms correctly Apply transforms correctly Dec 29, 2025
jplatte pushed a commit that referenced this pull request Sep 21, 2026
`schemars` only applies the transforms from its settings inside
`root_schema_for` and `take_definitions(true)`. `aide` calls neither when
building operations: it uses `subschema_for` and reads schemas back via
`GenContext::resolve_schema`, so every schema `aide` inlines into the
document was emitted untransformed and the generator settings were
silently ignored.

This is not limited to custom settings. `aide` defaults to
`SchemaSettings::draft07`, which ships `ReplaceUnevaluatedProperties`,
`RemoveRefSiblings` and `ReplacePrefixItems`, so a query struct with a
tuple field emitted draft 2020-12 `prefixItems` into a draft 7 document.

Add `GenContext::resolve_schema_transformed` and
`GenContext::apply_transforms`, and use them wherever a resolved or
inline schema is embedded directly: `parameters_from_schema` (which
covers `Path`, `Query`, typed routing and `serde_qs`), the request body
and response media types for `Json` and both `Form` extractors, and the
header schema for `TypedHeader`.

Schema references are deliberately left alone, since the definitions they
point at are already transformed by `take_definitions(true)` when they are
merged into the document.

`TypedPath` needs care in the other direction: it reads its description
out of `root_schema_for`, which has already run the transforms, so reusing
that schema for the parameters would transform them twice. `Transform`
carries no idempotency guarantee, so it now takes the parameters from
`subschema_for` like every other caller of `parameters_from_schema`.

Supersedes #230, which fixed `parameters_from_schema` but whose
`operation_input_json` hunk transformed a clone that was only read for its
description and then discarded, and which left the other five sites
untouched.

Co-authored-by: Diggory Blake <diggsey@googlemail.com>
@jplatte

jplatte commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Merged in #301.

@jplatte jplatte closed this Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants